<?php
namespace Common\Controller;
use Think\Controller;
/**
 * 公共继承控制器
 */
class BasicController extends Controller
{
    public function __construct(){
      parent::__construct();
      $this->isLogin();
      $this->rule();
      $this->menuInit();
      $this->webConf();
    }
    public function isLogin(){
      $user = getLoginUserInfo();
      if(!$user){
        $this->error("您尚未登录",U('Admin/Login/index'));
      }
    }
    public function webConf(){
      $this->assign('webConf',F('web_conf')?F('web_conf'):'');
    }
    public function rule($ruleName){
      $user = getLoginUserInfo();
      if($user['level'] !=2){
        $auth = new \Think\Auth();
        $ruleName = $ruleName?$ruleName:MODULE_NAME.'/'.CONTROLLER_NAME;
        $res = $auth->check($ruleName,$user['user_id']);
        if(!$res){
          $this->error('您没有权限操作');
        }
      }
    }
    public function menuInit(){
      $user = getLoginUserInfo();
      $menu = D('Menu')->getAdminNav();
      if($user['level']!=2){
      foreach ($menu as $k => $v) {
        $ruleName = $v['m'].'/'.$v['c'];
        $auth = new \Think\Auth();
        $res = $auth->check($ruleName,$user['user_id']);
        if(!$res){
          unset($menu[$k]);
        }
      }
    }
      $this->assign('username',$user['username']);
      $this->assign('nav',$menu);
    }
}
